#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int judge(int j)
{
	while (j)
	{
		if (j % 16 > 9)
			return -1;
		else 
		j /= 10;
	}
	return 1;
}

int main()
{
	int t, l, r;
	scanf("%d", &t);
	int a[200005], b[200005], c[200005]={0};
	for (int i = 0; i < t; i++)
		scanf("%d%d", &a[i], &b[i]);
	for (int i = 0; i < t; i++)
	{
		for (int j = a[i]; j <= b[i]; j++)
		{
			int ret=judge(j);
			if (ret > 0)
				c[i]++;
		}
	}
	for (int i = 0; i < t; i++)
	{
		printf("%d\n", c[i]);
	}
}